//@author A0094511L
///@class SyntaxHighlighter
///@Description This class is used by custom lineEdit class to highlight syntaxes that are of the same
///				format as the keywords defined. Regular expressions are used to identify the correct
///				syntaxes. There are two syntaxes. 
///				1. Regex to check if the text is a keyword. Set to highlighted color
///				2. Regex to check if the text is within quotation marks. Set to normal color, even if
///				   the text within the quotation marks is a keyword.
///				This class inherits from QSyntaxHighlighter class to reimplement the virtual function
///				highlightblock in order to set the rules for highlighting

#ifndef SYNTAXHIGHLIGHTER_H
#define SYNTAXHIGHLIGHTER_H

#include <QObject>
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QString>

class SyntaxHighlighter : public QSyntaxHighlighter{
	Q_OBJECT

public:

	//@brief Default Constructor of SyntaxHighlighter Class
	SyntaxHighlighter(QTextDocument *parent = 0); 
protected:

	//@brief Reimplemented virtual function of Qt QSyntaxHighlighter class
	//		 Highlights the given text block. This function is called when necessary by the rich text engine
	//	     i.e. on text blocks which have changed.
	 void highlightBlock(const QString&);

private:

	 //@brief Function is to set the color for highlighting to the private QBrushes
	 void setColor();

	 //@brief Function is to set the color to be used for highlighting to the respective textCharFormats
	 void setTextCharFormat();

	 //@brief Function is to define all regular expressions to be used in the highlighting rules
	 void defineRegularExpressions();

	 //@brief Function matches the string passed in to the regex and sets the format of the text accordingly.
	 void highlightCharbyChar(QRegExp, QTextCharFormat, const QString&);

	//private members to store the regular expressions for keywords and quotation marks
	QRegExp _keyWordRegex;
	QRegExp _quotationRegex;

	//private strings to store the patterns to be set in the above 2 regexes
	static const QString PATTERN_KEYWORD;
	static const QString PATTERN_QUOTATIONSMARK;

	//private formats to save the formatting in terms of font weight and font color
	QTextCharFormat _normalFormat;
	QTextCharFormat _highlightedFormat;

	QBrush _normalFormatBrush;
	QBrush _highlightedFormatBrush;

};

#endif
